package com.yc.supermarket.service.impl;

import com.yc.supermarket.entity.Manufacturer;
import com.yc.supermarket.entity.ProductType;
import com.yc.supermarket.mapper.ManufacturerMapper;
import com.yc.supermarket.mapper.ProductTypeMapper;
import com.yc.supermarket.service.ManufacturerService;
import com.yc.supermarket.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ManufacturerServiceImpl implements ManufacturerService {

    private ManufacturerMapper mapper;

    @Override
    public Map<String, Object> findByTrem(Manufacturer manufacturer) {
        SqlSession session = MybatisUtil.getSession();
        mapper = session.getMapper(ManufacturerMapper.class);
        List<Manufacturer> list = mapper.findByTrem(manufacturer);
        //创建hashmap存储数据
        Map<String, Object> m = new HashMap<>();
        if (null == list ) {
            m.put("code", 600);
            m.put("msg", "暂无数据");
        } else {
            m.put("code", 200);
            m.put("msg", "成功");
            m.put("data", list);
        }
        MybatisUtil.close(session);
        return m;
    }

    @Override
    public boolean add(Manufacturer manufacturer) {
        SqlSession session = MybatisUtil.getSession();
        mapper = session.getMapper(ManufacturerMapper.class);
        boolean result = mapper.add(manufacturer);
        return result;
    }

    @Override
    public boolean update(Manufacturer manufacturer) {
        SqlSession session = MybatisUtil.getSession();
        mapper = session.getMapper(ManufacturerMapper.class);
        boolean result = mapper.update(manufacturer);
        return result;
    }
}
